package be.castanea.client.services;

import be.castanea.client.services.util.GenericCommand;
import be.castanea.client.delegate.ServerDelegate;
import be.castanea.client.model.Mob;
import be.castanea.client.model.Movement;
import be.castanea.common.util.PositionEvent;
import be.castanea.common.JoinEvent;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;

/**
 * Castanea
 * 2009
 * @author Geert van Leemputten, Steven Rymenans, Bart Van Hooydonck
 */
public class AddMob extends GenericCommand {

    @Override
    public void execute(float interpolation) {
        PositionEvent position = (PositionEvent) event;
        float[] locationArr = position.getLocation();
        Vector3f location = new Vector3f(locationArr[0], locationArr[1], locationArr[2]);
        float[] rotationArr = position.getRotation();
        Quaternion rotation = new Quaternion(rotationArr);
        Movement movement = new Movement(position.getMovement());

        Mob mob = new Mob(event.getOriginator(), location, rotation, movement);
        getWorld().addMob(mob);

        if (event instanceof JoinEvent) {
            ServerDelegate.dispatchJoinReply(event.getOriginator());
        }
    }
}
